package cn.sciento.transfer.api.controller.v1;

import cn.sciento.core.iam.ResourceLevel;
import cn.sciento.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.sciento.core.util.Results;
import cn.sciento.starter.keyencrypt.core.Encrypt;
import cn.sciento.transfer.app.service.ProducerConfigService;
import cn.sciento.transfer.domain.entity.ConsDbConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"Producer Cons Init (Site Level)"})
@RestController("ProducerConsInitSiteController.v1")
@RequestMapping({"/v1/producer-cons-init"})
public class ProducerConsInitSiteController {
  @Autowired
  private ProducerConfigService producerConfigService;
  
  @ApiOperation("数据初始化，DB与租户维度,注意tenant维度需要传对应的db配置,eg:{xxx:xxx,consTenantConfigList:{}")
  @Permission(level = ResourceLevel.SITE)
  @PostMapping
  public ResponseEntity<ConsDbConfig> createProducerConfig(@Encrypt @RequestBody ConsDbConfig consDbConfig) {
    return Results.success(this.producerConfigService.initHistoryData(consDbConfig));
  }
}
